package book;
import java.util.ArrayList;
import database.*;
import databaseInterface.*;
import dataPO.*;
import others.*;

public class bookBLService implements bookInterface{
	BookManageInterface bm;
	CatalogManage cm;
	bookBLService(BookManageInterface bm,CatalogManage cm){
		this.bm=bm;
		this.cm=cm;
		this.bm.connect();
		this.cm.connect();
	}
	public ArrayList<BookPO> getBookByCategory(String Catalog){
	   	 ArrayList<BookPO> bp;
		 bp=bm.queryByCatalog(Catalog);
	     return bp;
	}
	public ArrayList<BookPO> searchBookByTitle(String title){
		ArrayList<BookPO> bp;
		bp=bm.queryByTitle(title);
		return bp;
	}
	public ArrayList<BookPO> searchBookByAuthor(String author){
		ArrayList<BookPO> bp;
		bp=bm.queryByAuthor(author);
		return bp;
	}
	public ArrayList<BookPO> searchBookByPress(String press){
		ArrayList<BookPO> bp;
		bp=bm.queryByPress(press);
		return bp;
	}
	public ArrayList<BookPO> searchBookByISBN(String isbn){
		ArrayList<BookPO> bp;
		bp=bm.queryByISBN(isbn);
		return bp;
	}
	public void end(){
		bm.close();
		cm.close();
	}
	public ResultMessage addBookCatalog(String catalog){
		boolean isexit=false;
		isexit=cm.query(catalog);
		if(!isexit){
			cm.insert(catalog);
			return ResultMessage.Succeed;
		}
		else{
			return ResultMessage.Exist;
		}
	}
	public ResultMessage delBookCatalog(String catalog){
		cm.delete(catalog);
		return ResultMessage.Succeed;
	}
}
